import React from 'react'
import { NavBar, Button, InputItem, TextareaItem } from 'antd-mobile';
import AvatarSelect from '../../component/avatarSelector/avatarSelector'
import { Redirect } from 'react-router-dom'

import { connect } from 'react-redux'
import {update} from '../../redux/user_redux'


@connect(
    state=>state.user,
    { update }
)
class GeniusInfo extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            title: '',
            desc: ''
        }
    }

    handleChange(key, value) {
        this.setState({
            [key]: value
        })
    }
    render() {
        console.log(this.props.redirectTo)

        const path = this.props.location.pathname
        const redirectTo = this.props.redirectTo
        return (
            <div>
                {redirectTo && redirectTo !== path?<Redirect to={this.props.redirectTo}/> : ''}
                <NavBar mode="dark" >牛人完善信息页</NavBar>
                {/* 这个不理解 组件传值 */}
                <AvatarSelect
                    selectAvatar={(imgname)=>{
                        this.setState({
                            avatar: imgname
                        })
                    }}
                >
                </AvatarSelect>
                <InputItem
                    onChange={(item) => this.handleChange('title', item)}
                >求职岗位</InputItem>
                <TextareaItem
                    title="个人简介"
                    onChange={(item) => this.handleChange('desc', item)}
                    rows={3}
                />
                <Button
                 type="primary"
                 onClick={()=>{
                     this.props.update(this.state)
                 }}
                 >保存</Button>
            </div>
        )
    }
}

export default GeniusInfo

